import React,{Component,View,StyleSheet,Text,ListView,LayoutAnimation,UIManager } from 'react-native';
import DayRecord from './dayRecord';

import {bindActionCreators} from 'redux';
import * as mainScreenActions from '../../actions/mainScreenActions';
import { connect } from 'react-redux';

class bwlist extends Component {
  static propTypes = {
  };
  componentWillMount(){
  }
  constructor(props) {
    super(props);
    //LayoutAnimation.configureNext(LayoutAnimation.Presets.spring);
    this.state={
      //dataSource:['高','梁','南','奉','大','高','梁','南','奉','大'],
      //ifSelect:[1,0,0,0,0]
    }
  }
  //选择每一个list时的回调
  _selectItem(e,index){
    //alert("222222")
    //选择的项目高亮显示
    var temp=[0,0,0,0,0];
    temp[index]=1;
    LayoutAnimation.configureNext(LayoutAnimation.Presets.spring);
    this.setState({
      ifSelect:temp
    });
    //console.log('你选择了项目'+index);
  }
  onSelect=()=>{
    this.props.navigator.push({
      name: 'bwList'
    });
  };
  //得到list里面的数据的最大值
  getmaxAmount=()=>{
    var max=0;
    for (var i = this.props.dayrecord.length - 1; i >= 0; i--) {
      if(this.props.dayrecord[i].amount > max){
        max=this.props.dayrecord[i].amount;
      }
    };
    return max;
  };
  render() {
    //console.log(this.props.mapstate);
    var maxAmount=this.getmaxAmount();
    var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
    return (
      <ListView
        style={styles.contain}
        dataSource={ds.cloneWithRows(this.props.dayrecord)}
        renderRow={(rowData,sec,index) => <DayRecord
                                            navigator={this.props.navigator}
                                            //最大的量，用来作为进度条的最大值
                                            maxAmount={maxAmount}
                                            rowData={rowData} 
                                            index={index}>
                                          </DayRecord>} 
        //renderHeader={(e)=>this._renderHeader(e)}
      />
        
    );
  }
}

const styles = StyleSheet.create({
  contain:{
    flex:1,
    //paddingLeft:10,
    //paddingRight:10
    //backgroundColor:'red',

  }
});

//将全局state绑定到组件的props中
function mapStateToProps(state) {
  return { 
    //state字段key
    dayrecord: state.mainScreenRedux.bwmain.dayrecord,//在上面的组件实例化时存入 
  }
}
//绑定一个方法到props中
function mapDispatchToProps(dispatch) {
  return { 
    mapactions: bindActionCreators(mainScreenActions, dispatch) 
  }
}
//将全局的state绑定到组件中
export default connect(mapStateToProps,mapDispatchToProps)(bwlist);